package com.example.onlinetaxi.ui.activity;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Insets;
import android.os.Build;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.Window;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.widget.AutoCompleteTextView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import com.example.onlinetaxi.R;
import com.example.onlinetaxi.util.ScreenAdaptation;

public class BaseActivity extends AppCompatActivity {

    public static BaseActivity baseActivity;//传递给非activity的类使用
    public static Context mContext;//传递给非activity的类使用

    @SuppressLint("InlinedApi")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        baseActivity = this;//传递给非activity的类使用
        mContext = this.getBaseContext();//传递给非activity的类使用

        // 设置字体自适应屏幕
//        new ScreenAdaptation(getApplication(), 720, 1600).register();

        getWindow().requestFeature(Window.FEATURE_NO_TITLE);

        // 对当前版本进行判断
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

            Window window = getWindow();

            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS

                    | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);

            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

            window.setStatusBarColor(Color.TRANSPARENT);

            window.setNavigationBarColor(Color.TRANSPARENT);

            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);//实现状态栏图标和文字颜色为暗色

        }

        setContentView(R.layout.activity_main);

    }


    // 设置起点搜索框
    protected void setStartSearchToolBar() {
        Toolbar toolbar = findViewById(R.id.toolbar_search);
        setSupportActionBar(toolbar);

        // 设置取消按钮
        TextView cancel = toolbar.findViewById(R.id.cancel_search);
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        AutoCompleteTextView autoCompleteTextView = toolbar.findViewById(R.id.editaddress);
        autoCompleteTextView.setHint("您在哪儿上车");
        // 获取焦点
        autoCompleteTextView.setFocusable(true);
        autoCompleteTextView.requestFocus();

        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                BaseActivity.this.onBackPressed();
            }
        });
    }

    // 设置终点搜索框
    protected void setEndSearchToolBar() {
        Toolbar toolbar = findViewById(R.id.toolbar_search);
        setSupportActionBar(toolbar);

        // 设置取消按钮
        TextView cancel = toolbar.findViewById(R.id.cancel_search);
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        AutoCompleteTextView autoCompleteTextView = toolbar.findViewById(R.id.editaddress);
        autoCompleteTextView.setHint("选择您的终点");
        // 获取焦点
        autoCompleteTextView.setFocusable(true);
        autoCompleteTextView.requestFocus();

        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                BaseActivity.this.onBackPressed();
            }
        });
    }
}